<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Default_db extends CI_Model
{
	function getGenders()
	{
		$query = $this->db->get('genders');
		return $query->result();		
	}
	
	function getRoles()
	{
		$query = $this->db->get('roles');
		return $query->result();		
	}
	
	function getShifts()
	{
		$query = $this->db->get('shifts');
		return $query->result();		
	}
	
	function getEmployeeStatus()
	{
		$query = $this->db->get('employee_status');
		return $query->result();		
	}
	
	function getAnnouncements()
	{
		$this->db->limit(5);
		$this->db->order_by('announcement_id','desc');
		$this->db->select('a.subject, a.announcement, a.modified, b.firstname, b.lastname, b.image_id');
		$this->db->join('users b','b.id = a.modified_by','left');
		$query = $this->db->get('announcements a');
		return $query->result_array();
	}
	
	function saveImage($data, $item=false)
	{	
		if (!$item)
		{			
			$this->db->trans_start();
			$this->db->insert('images', $data);
			$item = $this->db->insert_id();
			$this->db->trans_complete(); 					
		}
		else
		{
			$this->db->trans_start();
			$this->db->where('id', $item);
			$this->db->update('images', $data);		
			$this->db->trans_complete();
		}
		return $item;	
	}
	function getImage($imgid)
	{	
		$this->db->where('image_id', $imgid);
		$query = $this->db->get('images');
		return $query->row_array();
	}
	
}

?>